package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceDataVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@Api(tags = "设备管理")
@RequestMapping("/iot")
@RestController
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    public ResponseResult syncProductList(){
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct(){
        List<ProductVo> list = deviceService.allProduct();
        return success(list);
    }

    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return success();
    }

    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> queryPage( DevicePageQueryDto devicePageQueryDto){
        PageResponse<DeviceVo> pageResponse = deviceService.queryPage(devicePageQueryDto);
        return success(pageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest request) {
        DeviceVo deviceVo = deviceService.queryDeviceDetail(request);
        return success(deviceVo);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        return deviceService.queryDevicePropertyStatus(request);
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        HashMap<String, String> map = deviceService.queryThingModelPublished(request);
        return success(map);
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备备注名称")
    public ResponseResult updateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return success();
    }

    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceRequest deleteDeviceRequest){
        deviceService.deleteDevice(deleteDeviceRequest);
        return success();
    }
}
